import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		info: {}, // 用户信息 phone token
		requestArr: [], // 请求队列
		orderType: "", // 订单类别 全部订单:orderAll,待付款:orderPending,未出行:orderNotTravel  用于tabbar页面
		stationStart:{}, // 选择的出发站信息
		stationEnd:{}, // 选择的到达站信息
		ticketDetail:{}, // 车票详情(查询车次购票)
		orderDetail:{}, // 订单详情
	},
	mutations: {
		// 更新用户信息
		updateInfo(state, payload) {
			state.info = Object.assign({}, state.info, payload);
		},
		// 更新请求队列
		updateRequestArr(state, payload) {
			state.requestArr.push(payload);
		},
		// 取消页面请求  --好像有坑,先不用吧 abort会走进拦截器fail--
		cancelRequest(state) {
			state.requestArr.forEach(item => {
				console.log("item", item)
				item && item.abort();
			});
			state.requestArr = []
		},
		// 更新订单类别
		updateOrderType(state, payload) {
			state.orderType = payload || "";
		},
		// 更新出发站点
		updateStationStart(state, payload) {
			state.stationStart = payload || {};
		},
		// 更新到达站点
		updateStationEnd(state, payload) {
			state.stationEnd = payload || {};
		},
		// 更新车票详情
		updateTicketDetail(state, payload) {
			state.ticketDetail = payload || {};
		},
		// 更新订单详情
		updateOrderDetail(state, payload) {
			state.orderDetail = payload || {};
		}
	},
	actions: {}
})
export default store
